﻿using System;
using System.Windows;
using System.Windows.Controls;
using Gao.Poker.App.ViewModel;
using Gao.Poker.Services;

namespace Gao.Poker.App.Game
{
    /// <summary>
    /// Interaction logic for EndContestView.xaml
    /// </summary>
    public partial class EndContestView : UserControl
    {
        private GameViewModel _viewModel;
        public GameViewModel ViewModel
        {
            get { return _viewModel; }
            set
            {
                _viewModel = value;
                DataContext = _viewModel;
            }
        }

        public Action<Boolean> CallBack;

        public EndContestView()
        {
            InitializeComponent();
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            CompetitionEntryService service = new CompetitionEntryService();
            CompetitionService cs = new CompetitionService();
            _viewModel.Competition = cs.GetCompetition(_viewModel.Competition.ID);

            service.Update(_viewModel.Competition, ViewModel.Rankings);

            if (_viewModel.Competition.State == 0)
            {
                _viewModel.Competition.State = 1;
                cs.Save(_viewModel.Competition);
            }

            TablesService ts = new TablesService();
            ts.Update(_viewModel.Competition.ID);
            CallBack(true);
        }
    }
}
